#ifndef _ABSTRACT_EVENT_QUEUE_H
#define _ABSTRACT_EVENT_QUEUE_H

#include "AbstractThread.h"
#include <list>
using namespace std;

#define MsgID int 

class AbstractEventQueue : public AbstractThread
{
public:
	AbstractEventQueue(bool start = true);
	virtual ~AbstractEventQueue(void);

	bool Stop(bool waitQuit = true);

	void PostEvent(MsgID id, void* lParam = NULL, void* wParam = NULL);
	void SendEvent(MsgID id, void* lParam = NULL, void* wParam = NULL);
	void SetThreadName(char* name);
protected:
	virtual void CleanUp();
	virtual void ProcessEvent(MsgID id, void* lParam, void* wParam) = 0;
	
private:
	typedef struct {
		MsgID id;
		void* lParam;
		void* wParam;
		pthread_cond_t* cond;
	} tEvent;
	void init();
	void PostEvent(tEvent* event);
	bool HasEvent();
	virtual void DoAction();
	static void* cleanup(void* param);

private:
	pthread_cond_t* m_cond;
	pthread_mutex_t* m_mutex;
	pthread_mutex_t* m_waitMutex;
	typedef list<tEvent*> tEventList;
	tEventList* m_eventList;
};

#endif //_ABSTRACT_EVENT_QUEUE_H
